package com.bookstore;

import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;

public class MenuListActivity extends ListActivity {
    /** Called when the activity is first created. */
	private static final int ACTIVITY_COMPRAR = 4;
	private static final int ACTIVITY_COMPRAS = 6;
	private static final int COMPRAR_ID = Menu.FIRST;
	private static final int COMPRAS_ID = Menu.FIRST + 1;
    
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		boolean result = super.onCreateOptionsMenu(menu);
		menu.add(0, COMPRAR_ID, 0, R.string.m_comprar);
		menu.add(2, COMPRAS_ID, 0, R.string.m_compras);
		return result;
	}
    
    @Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case COMPRAR_ID:
			comprar();
			return true;
		case COMPRAS_ID:
			compras();
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

    private void comprar() {
    	BookStoreActivity.viewCart = false;
		Intent i = new Intent(this, BuyActivity.class);
		startActivityForResult(i, ACTIVITY_COMPRAR);
	}
    private void compras() {
    	BookStoreActivity.viewCart = true;
		Intent i = new Intent(this, ViewListCartActivity.class);
		startActivityForResult(i, ACTIVITY_COMPRAS);
	}
}
